<?php
  include_once HGN_CORE_PATH."/hgn_res_form.inc";
  include_once HGN_CORE_PATH."/hgn_common_form.inc";

function hgn_res_basic_form_structure(){
  return array(
    'name'  => array(
      "#type" => "textfield",
      "#title"=> t("Name"),
      "#required" => TRUE,
      "#weight" => 1,
    ),
    'description'  => array(
      "#type" => "textarea",
      "#title"=> t("Description"),
      "#required" => TRUE,
      "#weight" => 2,
    ),
    'phone_number'  => array(
      "#type" => "textfield",
      "#title"=> t("Phone Number"),
      "#required" => TRUE,
      "#weight" => 3,
    ),
    'email'  => array(
      "#type" => "textfield",
      "#title"=> t("Email"),
      "#weight" => 4,
    ),
    'image_fid'=> array(
      '#type' => "managed_file",
      '#title'=> t("Image File"),
      '#progress_indicator' => "bar",
      '#upload_location'    => "public://img/dish",
      "#upload_validators"  => array("file_validate_extensions" => array("png gif jpg")),
      '#weight' => 5,
    ),
    'contactant_name'  => array(
      "#type" => "textfield",
      "#title"=> t("Contact Person's Name"),
      "#weight" => 6,
    ),
    
    'allow_delivery'  => array(
      "#type" => "checkbox",
      "#title"=> t("Allow Delivery"),
      "#weight" => 10,
    ),
    'allow_online_payment'  => array(
      "#type" => "checkbox",
      "#title"=> t("Allow Online Payment"),
      "#weight" => 11,
    ),
  );
}

function hgn_res_add_form($form,&$form_state){
  $form = hgn_res_basic_form_structure();
  
  hgn_form_add_address_field($form);
  hgn_res_form_add_manage_user_select_field($form);
  
  $form['submit'] = array(
    '#type' => 'submit',
    '#value'=> t("Submit"),
    "#weight" => 21,
  );
  return $form;
}


function hgn_res_add_form_submit($form,&$form_state){
  // testing info
  drupal_set_message("<pre>".print_r($form_state['values'],TRUE)."</pre>");
  
  include_once HGN_CORE_PATH."/hgn_db_res.inc";
  if(hgn_db_add_restaurant($form_state['values'])){
    drupal_set_message("Restaurant ".$form_state['values']['name']." has been added.");
  } else{
    drupal_set_message("An error has occured. Please contact the site admin.","error");
    $form_state['rebuild'] = TRUE;
  }
}
